package cmd

import (
	"fmt"

	"github.com/spf13/cobra"
)

var (
	uploadFiles []string
	host        string
)

func init() {
	rootCmd.AddCommand(uploadCmd)
	uploadCmd.Flags().StringVarP(&shopID, "shop", "S", "", "门店ID")
	uploadCmd.Flags().StringSliceVarP(&uploadFiles, "file", "F", []string{}, "上传文件")
	uploadCmd.Flags().StringVarP(&host, "host", "H", "http://localhost:3000", "dp-oper-web's host")
}

var uploadCmd = &cobra.Command{
	Use:              string(Upload),
	Short:            "Upload file to web",
	Long:             `Upload file to web`,
	TraverseChildren: true,
	Run: func(cmd *cobra.Command, args []string) {
		slog.Debugf("shopID => %s", shopID)
		slog.Debugf("host => %s", host)
		slog.Debugf("files => %s", uploadFiles)
		if len(args) == 0 {
			slog.Error("need arg. use: dp upload [options] search/shop/review ")
			return
		}
		switch args[0] {
		case string(Search):
			NewRunner().UploadSearchWithShopesAndReviews(host, uploadFiles)
		case string(Shop):
			NewRunner().UploadShops(host, uploadFiles)
		case string(Review):
			NewRunner().UploadShopReviews(shopID, host, uploadFiles)
		default:
			fmt.Println("invalid target: use search/shop/review")
		}

	},
}
